<?php

/**
 * 
 */
class Profile_model extends CI_Model {

    function __construct() {
        parent::__construct();
        $this->load->database();
    }

    public function validateOldPw() {
        $old_pass = md5($this->input->post('old_pass'));
        $sql_old = "select password from users where user_id=" . $this->session->userdata('sess_user_id') . "";
        $pw_old = $this->db->query($sql_old)->row_array();
        if ($pw_old['password'] != $old_pass) {
            return FALSE;
        }
        else
            return TRUE;
    }

    public function validateOldPwEm() {
        $old_pass = md5($this->input->post('pass'));
        $sql_old = "select password from users where user_id=" . $this->session->userdata('sess_user_id') . "";
        $pw_old = $this->db->query($sql_old)->row_array();
        if ($pw_old['password'] != $old_pass) {
            return FALSE;
        }
        else
            return TRUE;
    }

    public function validateOldEmail() {
        $old_email = $this->input->post('old_email');
        $sql_old = "select email from users where user_id=" . $this->session->userdata('sess_user_id') . "";
        $email_old = $this->db->query($sql_old)->row_array();
        if ($email_old['email'] != $old_email) {
            return FALSE;
        }
        else
            return TRUE;
    }

    public function changePassword() {
        $pass = md5($this->input->post('pass'));
        $sql = "UPDATE users set password='" . $pass . "' WHERE user_id=" . $this->session->userdata('sess_user_id') . "";
        $this->db->query($sql);
    }

    // redirect('/'); 



    public function changeEmail() {
        $new_email = $this->input->post('new_email');
        $sql = "UPDATE users set email='" . $new_email . "' WHERE user_id=" . $this->session->userdata('sess_user_id') . "";
        $this->db->query($sql);
    }

}

?>